//% color="#E2B539" iconWidth=50 iconHeight=40
namespace BLE_UART {

    //% block="Setting the BLE UART slave display name[STR]" blockType="command" 
    //% STR.shadow="string" STR.defl=UNIHIKER_K10
    export function setBleServer(parameter: any, block: any) {
        let str = parameter.STR.code
        Generator.addInclude(`DFRobot_K10BleUart`, `#include "DFRobot_K10BleUart.h"`);
        Generator.addObject(`DFRobot_K10BleUart`, `DFRobot_K10BleUart`, `ble;`);
        Generator.addCode(`ble.setBleServer(${str});`);
    }

    //% block="Set up the BLE UART host to connect to the[STR]" blockType="command"    
    //% STR.shadow="string" STR.defl=UNIHIKER_K10
    export function setBleMaster(parameter: any, block: any) {
        let str = parameter.STR.code
        Generator.addInclude(`DFRobot_K10BleUart`, `#include "DFRobot_K10BleUart.h"`);
        Generator.addObject(`DFRobot_K10BleUart`, `DFRobot_K10BleUart`, `ble;`);
        Generator.addCode(`ble.setBleMaster(${str});`);
    } 

    //% block="BLE UART connected?" blockType="boolean"    
    export function getConnectState(parameter: any, block: any) {
        Generator.addCode(`ble.getConnectState()`);
    }

    //% block="When the BLE UART receives data" blockType="hat"    
    export function dataCallback(parameter: any, block: any) {
        Generator.addSetup(`bleServiceCallback`,`ble.bleServiceCallback(&getBleDataCallback);`);
        Generator.addEvent("addEvent", "void", "getBleDataCallback", "String str", true);
    } 

    //% block="BLE UART messages" blockType="reporter"    
    export function messages(parameter: any, block: any) {
        Generator.addCode(`str`);
    } 

    //% block="BLE UART Send Byte[STR]" blockType="command"    
    //% STR.shadow="string" STR.defl=abc
    export function sendData(parameter: any, block: any) {
        let str = parameter.STR.code
        Generator.addCode(`ble.sendData(${str});`);
    } 
}

